package com.bleeth.fx.component;

import com.bleeth.fx.helper.ThemeHelper;
import com.bleeth.fx.layout.BaseBuilder;
import com.bleeth.fx.layout.RowBuilder;
import javafx.geometry.Pos;
import javafx.scene.layout.HBox;


/**
 * @author Sakura
 * @version 1.0
 * @date 2021-11-13 22:17
 **/
public class MTableQuery {


    private static double DEFAULT_ROW_HEIGHT = 50D;
    private RowBuilder rowBuilder;
    private int currentIndex = 0;

    public static MTableQuery create(Integer size) {
        MTableQuery mTableQuery = new MTableQuery();
        mTableQuery.rowBuilder = RowBuilder.create();
        mTableQuery.rowBuilder.setHeight(DEFAULT_ROW_HEIGHT).setSpacing(60D).setPadding(0D, 0, 0D, 60D)
                .addColumn(
                        BaseBuilder.create().setSpan(1).setSpacing(10D).setPos(Pos.CENTER),
                        BaseBuilder.create().setSpan(1).setSpacing(10D).setPos(Pos.CENTER),
                        BaseBuilder.create().setSpan(1).setSpacing(10D).setPos(Pos.CENTER),
                        BaseBuilder.create().setSpan(1).setSpacing(10D).setPos(Pos.CENTER)
                );
        return mTableQuery;
    }

    public MTableQuery addQuery(String name) {
        rowBuilder.addCell(3, MButton.builder().type(ThemeHelper.PRIMARY).text(name).width(70).height(30).build().make());
        return this;
    }

    public MTableQuery addActionItem(String name) {
        rowBuilder.addCell(currentIndex, MLabel.builder().text(name).build().make());
        rowBuilder.addCell(currentIndex, MTextInput.builder().build().make());
        currentIndex++;
        return this;
    }


    public HBox make() {
        HBox row = rowBuilder.getRow();
        return row;
    }


}
